package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcFormfactorDAO;
import com.virtium.vpc.hibernate.model.VpcDensity;
import com.virtium.vpc.hibernate.model.VpcFormfactor;

public class VpcFormfactorManager {
	private static ArrayList<VpcFormfactor> arrVpcFormfactor = null;

	public static ArrayList<VpcFormfactor> getAll() {
		try {
			if (arrVpcFormfactor != null && arrVpcFormfactor.size() > 0)
				return arrVpcFormfactor;
			VpcFormfactorDAO vpcFormfactorDAO = DAOFactory.getInstance()
					.getVpcFormfactorDAO();
			arrVpcFormfactor = new ArrayList<VpcFormfactor>();
			arrVpcFormfactor.addAll(vpcFormfactorDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcFormfactor;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcFormfactor> iterObject = arrVpcFormfactor.listIterator();
		while(iterObject.hasNext()){
			VpcFormfactor object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcFormfactor object = new VpcFormfactor();
			object.setText(text);
			VpcFormfactorDAO ObjectDAO = DAOFactory.getInstance().getVpcFormfactorDAO();
			ObjectDAO.save(object);
			arrVpcFormfactor = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcFormfactorDAO ObjectDAO = DAOFactory.getInstance().getVpcFormfactorDAO();
			VpcFormfactor object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcFormfactor = null;
		}catch(Exception ex){
			
		}
	}
}
